package net.com.hydroPK.net.packethandler;

import net.com.hydroPK.model.Player;
import net.com.hydroPK.Engine;

/**
 * File created by: Joshua
 * Created on 23/2/2010 at 3:51
 */
public class MagicOnItem {

    public void handlePacket(Player p, int packetId, int packetSize) {
        if ((p == null) || (p.stream == null)) {
            return;
        }

        int itemID = p.stream.readUnsignedWordBigEndianA();
        int i2 = p.stream.readUnsignedWordBigEndian();
        int itemSlot = p.stream.readUnsignedWordBigEndian();
        int i4 = p.stream.readDWord();
        int spellID = p.stream.readDWord(); // Some dodgey shit but meh it'll do, dont think it changes

        if (p.items[itemSlot] != itemID) {
            return;
        }
        switch (spellID) {
        //case 570474496: // High-Alchemy
            //if (System.currentTimeMillis() - p.lastAlch >= 1000) {
                //if (magicLvl(p) >= 55) {
                    //if (itemID != 995) {
                        //if (hasReq(p, nature, 1) && hasReq(p, fire, 5)) {
                            //gfx(p, 113, 713);
                            //Engine.playerItems.addItem(p, 995, getPercentageValue(Engine.items.getItemValue(itemID), 75));
                            //Engine.playerItems.deleteItem(p, fire, 5);
                            //Engine.playerItems.deleteItem(p, nature, 1);
                            //Engine.playerItems.deleteItem(p, itemID, itemSlot, 1);
                            //p.appendExperience(2000, 6);
                            //p.lastAlch = System.currentTimeMillis();
                        //} else {
                           // p.message("You dont have the required runes to cast this spell.");
                            //p.lastAlch = System.currentTimeMillis();
                        //}
                    //} else {
                      //  p.message("You cannot alch coins!");
                    //}
                //} else {
                  //  p.message("You need level 55 magic to use this spell.");
                    //p.lastAlch = System.currentTimeMillis();
                //}
            //} else {
              //  p.message("You need to wait before trying to high alch again!");
                //p.lastAlch = System.currentTimeMillis();
            //}
            //break;

        /*case 218152960: // Low-Alchemy
            if (p.magicDelay <= 0) {
                if (magicLvl(p) >= modernLvlReq[0]) {
                    if (hasReq(p, nature, 1) && hasReq(p, fire, 3)) {
                        gfx(p, 112, 712);
                        addItem(p, 995, 2);
                        deleteItems(p, fire, 3, nature, 1);
                        Engine.playerItems.deleteItem(p, itemID, itemSlot, 1);
                        magicXp(p, modernSpellXp[12]);
                        p.magicDelay = mainDelayInt;
                    } else {
                        sendMsg(p,
                                "You dont have the required runes to cast this spell.");
                        p.clickDelay = mainClickDelay;
                    }
                } else {
                    sendMsg(p,
                            "You need level " + modernLvlReq[12]
                            + " magic to use this spell.");
                    p.clickDelay = mainClickDelay;
                }
            } else {
                sendMsg(p, "You need to wait before casting a spell again.");
                p.clickDelay = mainClickDelay;
            }
            break;*/

        }
    }
    public static boolean hasReq(Player p, int ItemId, int amt) {
        return Engine.playerItems.hasPlayerItemAmount(p, ItemId, amt);
    }
    public static void gfx(Player p, int gfxID, int animID) {
        p.requestAnim(animID, 0);
        p.requestGFX(gfxID, 0);
    }
    public static int magicLvl(Player p) {
        return p.getLevelForXP(6);
    }
    public int getPercentageValue(int i, int percent) {
        int j = i / 100;
        int k = j * percent;
        return k != -1 ? k : 0;
    }
    public static int fire = 554;
    public static int water = 555;
    public static int air = 556;
    public static int earth = 557;
    public static int mind = 558;
    public static int body = 559;
    public static int law = 563;
    public static int cosmic = 564;
    public static int death = 560;
    public static int nature = 561;
    public static int chaos = 562;
    public static int blood = 565;
    public static int soul = 566;
    public static int bones = 526;
}
